import { getCache, setCache } from "#server/utils/context"; import { getCardById } from "../../service/card"; export default defineWrappedResponseHandler(async (event) => { const idParam = getRouterParam(event, "id"); if (!idParam) return R.throwError(400, "缺少卡片 ID", null); const id = parseInt(idParam); if (isNaN(id)) return R.throwError(400, "卡片 ID 格式不正确", null); const cacheKey = `card:${id}`; const cached = await getCache(cacheKey); if (cached) return R.success(cached); const card = await getCardById(id); if (!card) return R.throwError(404, "Card not found", null); await setCache(cacheKey, card, 60); return R.success(card); });